/**
 * @class MessageBox 基于Dialog的应用消息类
 */
define('core/panel/MessageBox', ['jQuery', 'core/panel/Dialog'], function( require ){
	var $ = require('jQuery'),
		Dialog = require('core/panel/Dialog'),
		mix = K.mix,
		extend = K.extend;

	var MessageBox = extend(function( opts ){
		this._initMBox( opts );
	}, Dialog);

	mix( MessageBox.prototype, {
		_initMBox: function( opts ){
			//Message Box的内部样式，窗口样式使用父类中的className(默认为panel-t1)
			this.boxClass = 'mbox-t1';
			/*
			 * 按钮列表，配置结构如下
			 	[
			 		{
						label: '确定',			//按钮名称
						action: function(){}	//click事件的回调
					}
			 	]
			 */
			this.buttonList = [];

			MessageBox.$super.call( this, opts );

			this._createContent();
		},
		_createContent: function(){
			var box = $('<div class="' + this.boxClass + '"/>');
			var	content = $('<div class="ct"/>');
			this._act = $('<div class="act cls"/>');

			box.append( content );
			box.append( this._act );

			this.setContent( box );
			//改写content
			this._bd = content;
			this.setContent( this.content );
			this.setButton( this.buttonList );
		},
		/**
		 * 设置按钮列表，配置结构如下
			[
				{
					label: '确定',			//按钮名称
					action: function(){}	//click事件的回调
				}
			]
		 */
		setButton: function( buttonList ){
			var ins = this,
				btnHTML = [];
			this._act.empty();
			K.forEach( buttonList, function( btn ){
				var b = $('<div class="btn"><input type="button" value="' + btn.label + '" title="' + btn.label + '"></div>');
				b.appendTo( ins._act );
				if( btn.action ){
					b.click(function(){
						btn.action.call( ins, btn );
					});
				}
			});
		}
	});

	//静态方法
	mix( MessageBox, {
		/**
		 * 在Dialog中打开一个新的页面
		 * @static
		 * @param {String}	url			页面URL
		 * @param {Integer}	width		窗口宽度
		 * @param {Integer} height		窗口高度
		 * @param {String}	title		窗口标题
		 * @param {String}	className	窗口样式(默认使用Dialog的默认值:panel-t1)
		 * @return {Dialog}
		 */
		open: function( url, width, height, title, className ){
			var win = new KWindow({
				url: url,
				width: width,
				height: height,
				title: title,
				className: className||'panel-t1'
			});
			win.show();
			return win;
		}
	});

	return MessageBox;
});
